package gcosc.fun.hly.fastsso.controller;


import gcosc.fun.hly.fastsso.domain.Bo.PageQuery;
import gcosc.fun.hly.fastsso.domain.SsoUser;
import gcosc.fun.hly.fastsso.result.Result;
import gcosc.fun.hly.fastsso.result.TableDataInfo;
import gcosc.fun.hly.fastsso.service.SsoUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 用户
 *
 * @author ruoyi
 * @date 2023-12-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sso/user")
public class SsoUserController {

    private final SsoUserService iSsoUserService;

    /**
     * 查询用户列表
     */
    @GetMapping("/list")
    public TableDataInfo<SsoUser> list(SsoUser bo, PageQuery pageQuery) {
        return iSsoUserService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户列表
     */
//    @PostMapping("/export")
//    public void export(SsoUserBo bo, HttpServletResponse response) {
//        List<SsoUserVo> list = iSsoUserService.queryList(bo);
//        ExcelUtil.exportExcel(list, "用户", SsoUserVo.class, response);
//    }

    /**
     * 获取用户详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public Result<SsoUser> getInfo(@PathVariable Long id) {
        return Result.ok(iSsoUserService.queryById(id));
    }

    /**
     * 新增用户
     */
    @PostMapping()
    public Result<Void> add(@RequestBody SsoUser bo) {
        return Result.ok(iSsoUserService.insertByBo(bo));
    }

    /**
     * 修改用户
     */
    @PutMapping()
    public Result<Void> edit(@RequestBody SsoUser bo) {
        return Result.ok(iSsoUserService.updateByBo(bo));
    }

    /**
     * 删除用户
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public Result<Void> remove(@PathVariable Long[] ids) {
        return Result.ok(iSsoUserService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
